package com.park.carpark.service;


import com.park.carpark.mapper.ParkMapper;
import com.park.carpark.pojo.Parking_Register;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.text.ParseException;
import java.util.List;

@Service
public class ParkServiceImpl implements ParkService {

    @Resource
    private ParkMapper parkMapper;

    public ParkMapper getParkMapper() {
        return parkMapper;
    }

    public void setParkMapper(ParkMapper parkMapper) {
        this.parkMapper = parkMapper;
    }

    public int addCarMsg(Parking_Register park) {
        return parkMapper.addCarMsg(park);
    }

    public List<Parking_Register> showParkMsg() {
        return parkMapper.showParkMsg();
    }

    public Parking_Register showOutMsg(String car_ID) {
        return parkMapper.showOutMsg(car_ID);
    }

    public int updateMsg(Parking_Register park) {
        return parkMapper.updateMsg(park);
    }

    public Parking_Register getTime(Parking_Register park) {
        return parkMapper.getTime(park);
    }

    public int updatePrice(Parking_Register park) {
        Parking_Register time = parkMapper.getTime(park);
        double hours=time.getSum_time()/60;
        double money=0;
        if (hours>0&&hours<=0.5){
            money=2.5;
        }else if (hours>0.5){
            double newHours=Math.ceil(hours);
            money=newHours*5;
        }
        park.setPrice(money);
        int i = parkMapper.updatePrice(park);
        if (i>0){
            System.out.println("增加成功！");
        }else {
            System.out.println("增加失败!");
        }
        return parkMapper.updatePrice(park);
    }
}
